﻿[#include "../include/html_header.html"/]
<script type="text/javascript">
    $(function () {
        $("#baseForm").validate();
    });
    //获得城市
    function getResultCity(d) {
        $.post('findAllCity.htm', {"id": d},
                function (data) {
                    if (data.success) {
                        $("#itemcity").html("");
                        var select = "<select name='cityId' onchange='getResultCountry(this.value)'>";
                        for (var i = 0; i < data.ids.length; i++) {
                            select += "<option value='" + data.ids[i] + "'>&nbsp;" + data.citys[i] + "&nbsp;</option>";
                        }
                        select += "</select>";
                        getResultCountry(data.ids[0]);
                        $("#itemcity").append(select);
                    }
                }, "json");
    }
    //获得县、区
    function getResultCountry(a) {
        $.post('findAllCountry.htm', {"id": a},
                function (data) {
                    if (data.success) {
                        $("#itemarea").html("");
                        var select = "<select name='countryId'>";
                        for (var i = 0; i < data.ids.length; i++) {
                            select += "<option value='" + data.ids[i] + "'>&nbsp;" + data.areas[i] + "&nbsp;</option>";
                        }
                        select += "</select>";
                        $("#itemarea").append(select);
                    }
                }, "json");
    }

    function checkSubmit() {
        if ($("#provinceId").val() == '' || $("#provinceId").val() == null) {
            alert("请选择所在地址!");
            return;
        }
        if ($("#tel").val() == null && $("#phone").val() == null && $("#tel").val() == '' && $("#phone").val() == '') {
            alert("手机跟电话至少有一项必填");
            return;
        }
        $("#baseForm").submit();
    }
</script>

</head>
<body>
[#include "../include/html_header_top.html"/]

<div class="am-container">
    <div class="am-cf admin-main">
        <!-- sidebar start -->
        [#include "member_nav.html"/]
        <div class="admin-content">


        <div class="am-u-sm-12">
        <h3>现在的收货地址</h3>
       <table class="am-table">
           [#list list as address]
           <tr>
            <td>
                ${address.username!},${address.province.name!},${address.city.name!},
                ${address.country.name!},${address.detailaddress!},${address.postCode!},${address.tel!}
            </td>
               <td>
                   <a href="address_edit.htm?id=${address.id}" class="y44" target="_self">修改</a> |
                   <a href="address_delete.htm?id=${address.id}" class="w44">删除|</a>
                   <a href="address_default.htm?id=${address.id}">设为默认</a></span>
               </td>
           </tr>
           [/#list]
       </table>

        <h3>新增收货地址<span class="gray">（手机、固定电话选填一项，其余均为必填）</span></h3>

        <form action="address_save.htm" class="am-form" id="baseForm" method="post">
            <table width="100%" border="0" cellspacing="2" cellpadding="0">
                <tr>
                    <td height="25" width="70" align="right" style="color:#333;">收货人：</td>
                    <td width="648"><input name="username" type="text" maxlength="20" class="address_input required"/>
                    </td>
                </tr>
                <tr>
                    <td height="25" align="right" style="color:#333;">性别：</td>
                    <td width="648"><input type="radio" name="gender" value="true" checked/>男&nbsp;&nbsp;&nbsp;&nbsp;
                        <input type="radio" name="gender" value="false"/>女
                    </td>
                </tr>
                <tr>
                    <td height="25" align="right" style="color:#333;">所在地址：</td>
                    <td width="648">
                        <select id="provinceId" name="provinceId" onchange="getResultCity(this.value)">
                            <option value="">--请选择--</option>
                            [#list plist as province]
                            <option value="${province.id!}">${province.name!}</option>
                            [/#list]
                        </select>
                        <span id="itemcity"></span>
                        <span id="itemarea"></span>

                    </td>
                </tr>
                <tr>
                    <td height="25" align="right" style="color:#333;">详细地址：</td>
                    <td width="648"><input name="detailaddress" type="text" size="50" maxlength="100"
                                           class="address_input required"/></td>
                </tr>
                <tr>
                    <td height="25" align="right" style="color:#333;">邮政编码：</td>
                    <td width="648"><input name="postCode" type="text" maxlength="15" class="address_input required"/>
                    </td>
                </tr>
                <tr>
                    <td height="25" align="right" style="color:#333;">手机：</td>
                    <td width="648"><input type="text" id="tel" name="tel" maxlength="11" class="address_input digits"/>手机跟电话至少有一项必填
                    </td>
                </tr>
                <tr>
                    <td height="25" align="right" style="color:#333;">固定电话：</td>
                    <td width="648"><input type="text" id="areaCode" name="areaCode" size="4" maxlength="4"
                                           class="digits"/>-
                        <input type="text" id="phone" name="phone" size="14" maxlength="10" class="digits"/>-
                        <input type="text" id="extNumber" name="extNumber" size="6" maxlength="6" class="digits"/>
                        区号(3到4位数字，可选)-电话号码(7到8位数字)-分机号(最多6位数字，可选)
                    </td>
                </tr>
                <tr>
                    <td height="25" align="right">&nbsp;</td>
                    <td width="648"><input name="isDefault" type="checkbox" value="false"/>设为默认地址</td>
                </tr>
                <tr>
                    <td height="25" align="right">&nbsp;</td>
                    <td width="648"><input type="button" value="保&nbsp;&nbsp;存 " onclick="checkSubmit();"/>&nbsp;&nbsp;
                        <input type="reset" value="重&nbsp;&nbsp;置"/></td>
                </tr>
            </table>
        </form>
    </div>
            </div>
        </div>
    </div>
    <div class="clear"></div>
</div>
[#include "../include/footer.html"/]
</body>
</html>